<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!doctype html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>安城金融图书管理平台</title>
		<link rel="stylesheet" href="${ pageContext.request.contextPath }/css/bootstrap.min.css" type="text/css" />
		<script src="${ pageContext.request.contextPath }/js/jquery-1.11.3.min.js" type="text/javascript"></script>
		<script src="${ pageContext.request.contextPath }/js/bootstrap.min.js" type="text/javascript"></script>
		<!-- 引入自定义css文件 style.css -->
		<link rel="stylesheet" href="${ pageContext.request.contextPath }/css/style.css" type="text/css" />
		<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
		<style>
			body {
				margin-top: 20px;
				margin: 0 auto;
			}
				.carousel-inner .item img {
				width: 100%;
				height: 300px;
			}
			td{
				border:1px solid #0D0D0D;
				text-align:center;
				vertical-align:middle;
			}
		
		</style>
		<script type="text/javascript">
		 function showDetail(oid,bid){
			 //alert(1);		
			 if($("#but"+bid).val()== "借阅详情"){
		 $.post("${ pageContext.request.contextPath}/BookBorrowItemsServlet",{"method":"findByOid","oids":oid},function(data){
			 //alert(JSON.stringify(data));
			//$("#lb"+bid).css("display","");
			$("#tb"+bid).append("<tr id='tr"+bid+"'><td>"
			+"<table class='table table-bordered' id='lb"+bid+"' >"
			+"	<tr  style='background-color: #00EEEE' >"
			+"		<th>图片</th>"
			+"		<th>编号</th>"
			+"		<th>书名</th>"
			+"		<th>借阅数量</th>"
			+"		<th>预期归还时间</th>"
			+"		<th>续借天数</th>"
			+"		<th>归还状态</th>"
			+"		<th>能否撤回</th>"
			+"	</tr> "
			
			+"</table>"
			+"</td></tr>");
			 $(data).each(function(i,n){
				// $("#div"+oid).append("dddd");
					// 显示图片,名称,单价,数量
					
					//alert(JSON.stringify(n));
					var year = n.expeReturnTime.year+1900;
					var month = n.expeReturnTime.month+1;
					var day = n.expeReturnTime.date;
					var hours = n.expeReturnTime.hours;
					var minutes = n.expeReturnTime.minutes;
					var seconds = n.expeReturnTime.seconds;
					if(month>12){
						month =1;
					}
					//alert(minutes.toString().length)
					if(minutes.toString().length==1){
						minutes="0"+minutes;
					}
					if(seconds.toString().length==1){
						seconds="0"+seconds;
					}
					var ststus = '';
					var xj='';
					var ch='';
				
					if(n.bstatus==0){
						ststus ='借阅中。。。';
						xj="<a href='' role='button' data-toggle='modal' data-target='#myModal'>续借</a>";
						$("#bookBorrowing_id").val(n.bookBorrowing_id);
						ch ="<font color='red'>不可撤回</font>";
					
					}else if(n.bstatus==1){
						ststus ='续借中。。。';
						xj=n.renewDays;
						ch ="<font color='red'>不可撤回</font>";
					}else if(n.bstatus==2){
						ststus ='已归还';
						xj=n.renewDays;
						ch ="<font color='red'>不可撤回</font>";
					}else if(n.bstatus==4){
						ststus ='等待管理员确认';
						ch ="<a href='${ pageContext.request.contextPath }/AdminBookBorrowServlet?method=send&bookBorrowing_id="+n.bookBorrowing_id+"&flag=3'>可撤回</a>";
						xj=n.renewDays;
					}else if(n.bstatus==5){
						ststus ='管理员驳回';
						xj=n.renewDays;
						ch ="<font color='red'>不可撤回</font>";
					}else if(n.bstatus==6){
						ststus ='已撤回';
						xj=n.renewDays;
						ch ="<font color='red'>不可撤回</font>";
					}
					
					
					
					$("#lb"+bid).append(" <tr style='border:1px solid #0D0D0D;' class='warning' id='lb'"+n.bookBorrowing_id+" > <td ><img width='60' height='65' src='${pageContext.request.contextPath}/"+n.book_image+"'></td><td>"+n.book_number+"</td>	<td>"+n.books_name+"</td><td>"+n.total+"</td><td>"+year+"-"+month+"-"+day+"&nbsp;"+hours+":"+minutes+":"+seconds+"</td><td>"+xj+"</td><td>"+ststus+"</td> <td>"+ch+"</td>");
					
					
				});
			 },"json"); 
		 $("#but"+bid).val("关闭");
			 }else{
				 $("#div"+bid).html("");
				 $("#but"+bid).val("借阅详情");
				 //$("#lb"+bid).css('display','none'); 
				 $("#tr"+bid).remove();
			 }
		 }
		
			$(document).ready(function(){
				  $("form").submit(function(e){
					 
					  var reg = /^[0-9]*$/;
					  if (!reg.test($("#renewDays").val())) {
					  alert("请输入正整数！")
					  return false;
					  }
					  
					  var rebowDays = $("#rebowDays").val();
					  
					  var total = $("#renewDays").val()
					  if(total==''){
						  alert("续借天数不能为空！");
					    	return false;
					  }
					 
					  if(parseInt(total)>parseInt(rebowDays)){
					    	alert("续借天数不能超过"+rebowDays+"天");
					    	return false;
					    }
				    
				  });
				});
		
		 	
		 		function backup(id){
		 			alert(id);
		 			
		 				$.post("${ pageContext.request.contextPath }/AdminBookBorrowServlet",{"method":"send","bookBorrowing_id":id,"flag":"3"},function(data){
		 	 				/* if(data == 1){
		 	 					$("#s1").html("<font color='green'>用户名可以使用</font>");
		 	 					$("#regBut").attr("disabled",false);
		 	 				}else if(data == 2){
		 	 					$("#s1").html("<font color='red'>用户名已经被占用</font>");
		 	 					$("#regBut").attr("disabled",true);
		 	 				} */
		 	 			});
		 		}
		 		
		 		
		 	
			
		</script>
	</head>

	<body>

		<%@ include file="menu.jsp" %>

		<div class="container">
			<div class="row">
			<c:if test="${fn:length(pageBean.list) == 0 }">
			<div style="margin-left: 20%">
				<h1>你还没有借过图书，去开启你的图书之旅吧~ </h1>
				
			</div>
			</c:if>
			<c:if test="${fn:length(pageBean.list) != 0 }">
				<div style="margin:0 auto; margin-top:10px;width:950px;">
					<strong>我的订单</strong>
					<table class="table table-bordered" >
						<c:forEach var="order" items="${ pageBean.list }">
						<tbody id="tb${ order.bookBorrowItems_id  }" >
							
							<tr class="success">
								<th colspan="5">
								<div style="float:left;width:50%">订单编号:${ order.bookBorrowItems_id }&nbsp;&nbsp;&nbsp;</div>
								
								<div style="float:left;width:30%">订单包含图书总数：${ order.count }本 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
								
<%-- 								<div style="float:left;width:20%"><a href="${ pageContext.request.contextPath }/BookBorrowItemsServlet?method=findByOid&oids=${ order.bookBorrowing_id }">详情</a></div>
 --%>								<div style="float:left;width:20%"><input type="button"  value="借阅详情" id="but${ order.bookBorrowItems_id }" onclick="showDetail('${ order.bookBorrowing_id }','${ order.bookBorrowItems_id }')"/></div>
								<%-- <c:if test="${ order.count == 1 }">
									<a href="${ pageContext.request.contextPath }/OrderServlet?method=findByOid&oid=${ order.oid }">续借</a>
								</c:if>
								<c:if test="${ order.count == 2 }">
									续借中...
								</c:if>
								<c:if test="${ order.count == 3 }">
									图书已归还
								</c:if> --%>
								
								</th>
							</tr>
							<%--<tr ">
								 <td>
								<table class="table table-bordered" id="lb${ order.bookBorrowItems_id  }" style="display:none">
									<tr  style="background-color: #00EEEE" >
										<th>图片</th>
										<th>书名</th>
										<th>借阅数量</th>
										<th>预期归还时间</th>
										<th>归还状态</th>
									</tr> 
								
								</table>
							 	</td> 
							</tr>--%>
						<%-- <c:forEach var="orderItem" items="${ order.orderItems }">
							
							<tr class="active">
								<td width="60" width="40%">
									<img src="${ pageContext.request.contextPath }/${ orderItem.book.book_image }" width="70" height="60">
								</td>
								<td width="30%">
									<a target="_blank">${ orderItem.book.book_name }</a>
								</td>
								<td width="20%">
									${ orderItem.book.inventory }
								</td>
								<td width="10%">
									${ orderItem.count }
								</td>
								<td width="15%">
									<span class="subtotal">${ orderItem.book.inventory }</span>
								</td>
							</tr>
							</c:forEach> --%>
						</tbody>
						</c:forEach>
						
					</table>
				</div>
				</c:if>
			</div>
			 <c:if test="${fn:length(pageBean.list) != 0 }">
			<div style="text-align: center;">
				<ul class="pagination">
				
					<li <c:if test="${ pageBean.currPage == 1 }">class="disabled"</c:if>><a href="${ pageContext.request.contextPath }/BookBorrowItemsServlet?method=findByUserId&currPage=${pageBean.currPage-1}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
					
					<c:forEach var="i" begin="1" end="${ pageBean.totalPage }">
						<li <c:if test="${ pageBean.currPage == i }">class="active"</c:if>><a href="${ pageContext.request.contextPath }/BookBorrowItemsServlet?method=findByUserId&currPage=${i}">${ i }</a></li>
					</c:forEach>
					<c:if test="${ pageBean.currPage == pageBean.totalPage }">
						<li class="disabled">
							<a href="#" aria-label="Next">
								<span aria-hidden="true">&raquo;</span>
							</a>
						</li>
					</c:if>
					<c:if test="${ pageBean.currPage != pageBean.totalPage }">
						<li>
							<a href="${ pageContext.request.contextPath }/BookBorrowItemsServlet?method=findByUserId&currPage=${pageBean.currPage+1}" aria-label="Next">
								<span aria-hidden="true">&raquo;</span>
							</a>
						</li>
					</c:if>
				</ul>
			</div>
			</c:if>
		</div>

		<%@ include file="under.jsp" %>
		
		
		<!-- Modal -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog" role="document">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">续借图书</h4>
	      </div>
	      <div class="modal-body">
	      	<form id="deptmanagerAction_save_do" name="Form1" action="${pageContext.request.contextPath}/BookBorrowServlet?method=renewDay" method="post">
                    <div class="form-group">
                        <label for="deptname">续借天数</label>
                        <input type="text" id="renewDays" name="renewDays" class="form-control"  placeholder="续借天数">
                        			<font color="red">最多只能续借${rebowDays}天</font>
                        <input type="hidden" id="bookBorrowing_id" name="bookBorrowing_id" class="form-control" >
                        <input type="hidden" id="idnum" name="idnum" class="form-control" >
                        <input type="hidden" id="rebowDays" value="${rebowDays }"  class="form-control" >
                        
                    </div>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	        <button type="submit" class="btn btn-primary">保存</button>
	      </div>
                </form>
	    </div>
	  </div>
	</div>
	</body>

</html>